package cn.wolfcode.trip.app.web.controller;

import cn.wolfcode.trip.base.service.ISignService;
import cn.wolfcode.trip.base.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/signs")
public class SignController {
    @Autowired
    private ISignService signService;

    /**
     * 获取时间数组
     * @param userId
     * @return
     */
    @GetMapping("/{userId}/time")
    public Object getSigntime(@PathVariable Long userId){
        List<String> list = signService.get(userId);
        return list;
    }

    /**
     * 获取字段
     * @param userId
     * @return
     */
    @GetMapping("/{userId}")
    public Object getSign(@PathVariable Long userId){
        return signService.getSign(userId);
    }
    /**
     * 设置积分和连续签到
     */
    @PostMapping("/{userId}")
    public Object setSign(@PathVariable Long userId){
        JSONResult result = new JSONResult();
        try {
            signService.setSign(userId);
        }catch (Exception e){
            e.printStackTrace();
            result.mark(e.getMessage());
        }
        return result;
    }
}
